// Declare all the functions we will need

function getAppletCode(localFile, remoteFile, ftpDir, ftpAddress, 
		ftpUsername, ftpPassword, redirectUrl) {
	var appletHtml = '<applet code="com.oxxo.gallery.ftp.FtpUploadApplet" width="250" ' +
		'height="100" archive="FtpUploadApplet.jar, lib/commons-net-ftp-2.0.jar">' +
		'<param name="localFile" value="'+ localFile +'" />' +
		'<param name="remoteFile" value="'+ remoteFile +'" />' +
		'<param name="ftpDir" value="'+ ftpDir +'" />' +
		'<param name="ftpAddress" value="'+ ftpAddress +'" />' +
		'<param name="ftpUsername" value="'+ ftpUsername +'" />' +
		'<param name="ftpPassword" value="'+ ftpPassword +'" />' +
		'<param name="redirectUrl" value="'+ redirectUrl +'" />' +
		'</applet>';
	
	return appletHtml;
};

function showApplet() {
	$("#ftpUploadAppletDiv").hide();
	$("#btnUpload").click(function() {
		var localFile = $("#browseFile").val();
		var remoteFile = localFile.split("\\").pop();
		var ftpDir = "/src/144";
		var ftpAddress = "fcogal02";
		var ftpUsername = "gallery";
		var ftpPassword = "*OXXO*80";
		var appletCode = getAppletCode(localFile, remoteFile, ftpDir, ftpAddress, ftpUsername, ftpPassword);
		$("#ftpUploadAppletDiv").html(appletCode);
		$("#ftpUploadAppletDiv").slideDown("slow");
	});
};


// Here we declare function for JQuery as soon as the dom is ready
$(document).ready(showApplet);